home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / ov143b.zip / TONE.C < prev    next >
C/C++ Source or Header  |  1993-01-04  |  2KB  |  53 lines

  1. /*  001  15-Apr-87  tone.c
  2.  
  3.         Copyright (c) 1987 by Blue Sky Software.  All rights reserved.
  4.  
  5.         NOTE:  This routine is very hardware and software dependent.
  6. */
  7.  
  8. #include <dos.h>
  9.  
  10. #define CLOCK_RATE (1193180L)          /* timer clock rate */
  11. #define TIMER_CTL  (67)                /* timer control port */
  12. #define TIMER_CNT  (66)                /* timer count port */
  13. #define READY_CMD  (182)               /* command to ready timer */
  14. #define PPI        (97)                /* Programmable Peripheral Interface */
  15. #define SPEAK_BITS (3)                 /* speaker control bits */
  16. #define FULL_DAY   (1573040L)          /* a full day in clock ticks */
  17. #define BIOS_TICKS (0x46CL)            /* ptr to bios clock ticks in low mem */
  18.  
  19.  
  20. /*****************************************************************************
  21.                                 T O N E
  22.  ****************************************************************************/
  23.  
  24. tone(fq,ticks) /* generate a tone for selected # clock ticks */
  25. unsigned fq, ticks;
  26. {
  27.    unsigned count;
  28.    unsigned long endtime, now, new;
  29.  
  30.    count = CLOCK_RATE / fq;            /* calculate timer count for freq */
  31.  
  32.    outp(TIMER_CTL,READY_CMD);          /* send timer count */
  33.    outp(TIMER_CNT,count % 256);
  34.    outp(TIMER_CNT,count / 256);
  35.  
  36.    outp(PPI,inp(PPI) | SPEAK_BITS);    /* turn on the speaker */
  37.  
  38.    /* determine what time it is in clock ticks and when to end */
  39.  
  40.    endtime = (now = *((long far *) BIOS_TICKS)) + ticks;
  41.  
  42.    /* kill time until the duration is up */
  43.  
  44.    while (now < endtime) {
  45.       new = *((long far *) BIOS_TICKS);
  46.       if (new < now)                           /* just in case its midnight */
  47.          now = new + FULL_DAY;
  48.       else
  49.          now = new;
  50.    }
  51.  
  52.    outp(PPI,inp(PPI) & ~SPEAK_BITS);   /* turn off the speaker */
  53. }